package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import dao.StringToImg_Repository;
import play.data.FormFactory;
import play.libs.Json;
import play.libs.concurrent.HttpExecutionContext;
import play.mvc.Controller;
import play.mvc.Result;

import javax.inject.Inject;
import java.util.concurrent.CompletionStage;

public class StringToImgController extends Controller{
   

        private final FormFactory formFactory;
    private final StringToImg_Repository stringToImgRepository;
    private final HttpExecutionContext ec;

    @Inject
    public StringToImgController(FormFactory formFactory, StringToImg_Repository stringToImgRepository, HttpExecutionContext ec) {
        this.formFactory = formFactory;
        this.stringToImgRepository = stringToImgRepository;
        this.ec = ec;
    }


    public CompletionStage<Result> StringToImg() {
        JsonNode json = request().body().asJson();
        String ImgStr = json.findPath("ImgStr").textValue();

        return stringToImgRepository.StringToImg(ImgStr).thenApplyAsync(_getTruckList -> {
            return ok(Json.toJson(_getTruckList));
        }, ec.current());
    }
    }

